<?php

class Admin_Model_Mobilevalidation {

    private $_dbtable;

    public function __construct() {
        $this->_dbtable = new Admin_Model_DbTable_Mobilevalidation();
    }

    public function fetchaAll() {
        $select = $this->_dbtable->select();
        $fetchAll = $this->_dbtable->fetchAll($select);
        $array = array();
        foreach ($fetchAll as $mobileData) {
            array_push($array, $this->formatData($mobileData));
        }
        return $array;
    }

    /**
     * 
     * @param type $data
     * @return type
     */
    public function addNew($data) {
        return $this->_dbtable->insert($data);
    }

    /**
     * 
     * @param type $data
     * @param type $id
     * @return type
     */
    public function update($data, $id) {
        return $this->_dbtable->update($data, "id = $id ");
    }

    /**
     * 
     * @param type $data
     * @param type $mobile
     * @return type
     */
    public function updateByMobile($data, $mobile) {
        $byMobile = $this->getByMobile($mobile);
        return $this->update($data, $byMobile['id']);
    }

    /**
     * 
     * @param type $mobile
     * @return type
     */
    public function getByMobile($mobile) {
        $fetchaAll = $this->fetchaAll();
        foreach ($fetchaAll as $mobileData) {
            if ($mobileData['mobile'] == $mobile) {
                return $mobileData;
            }
        }
    }

    /**
     * 
     * @param type $data
     * @return type
     */
    private function formatData($data) {
        $array = array(
            'id' => $data['id'],
            'mobile' => $data['mobile_number'],
            'code' => $data['verification_code'],
            'isVerified' => $data['verified'],
            'message' => $data['message_queue'],
            'notificationId' => $data['notification_id']
        );
        return $array;
    }

}

